﻿using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using System.Collections.Generic;

namespace EpisodeWizard.App.WizardPages
{
	public partial class WizardPageIdentify : CoreUI.WizardPage
	{

		public WizardPageIdentify()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Called each time this page is dispayed
		/// </summary>
		private void WizardPageIdentify_EnterPage()
		{
			CoreUI.ThreadHelpers.StartThreadedAction(new ThreadedIdentify(), true);
			Core.Program.GetInstance().OnFileListValuesChanged();
		}

	}



	/// <summary>
	/// Initialize the plugins in a separate thread
	/// So that the UI can still update properly
	/// </summary>
	public class ThreadedIdentify : Core.ThreadedAction
	{
		public override void Action()
		{
			OnStart();

			int i = 0;
			foreach (Core.EpisodeFile File in Core.Program.GetInstance().EpisodeFiles)
			{
				if (CancelRequest)
				{
					break;
				}

				++i;
				int Percentage = i * 100 / Core.Program.GetInstance().EpisodeFiles.Count;
				OnProgress(Percentage, "Identifying files", i + "/" + Core.Program.GetInstance().EpisodeFiles.Count);
				File.Identify();
			}

			OnEnd();
		}

	}


}
